<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="ck" uri="http://ckeditor.com"%> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>收货地址列表</title>
<link href="${pageContext.request.contextPath}/css/slider.css"
	rel="stylesheet" type="text/css" />
<link href="${pageContext.request.contextPath}/css/common.css"
	rel="stylesheet" type="text/css" />
<link href="${pageContext.request.contextPath}/css/index.css"
	rel="stylesheet" type="text/css" />
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
<script type="text/javascript">

	function dele(id) {
		var r = confirm("确定删除吗？");
		if (r == true) {
			window.location.href = "${pageContext.request.contextPath }/delShip.action?id="
					+ id;
		} else {
		}
	}
	function choose(id) {
		window.location.href = "${pageContext.request.contextPath }/chooseShip.action?id="+id;
	}
	function update(id){
		window.location.href = "${pageContext.request.contextPath }/updateShip.action?id="+id;
	}
	
	//批量删除
	$(function(){
	    $("#deleteSkills").click(function(){
	        //判断是否至少选择一项
	        var checkedNum = $("input[name='ids']:checked").length;
	        if(checkedNum==0){
	            alert("请至少选择一项");
	            return;
	        }
	        if(confirm("确定要删除所选收货地址吗？")){
	            //这个数组存储要删除的数据的id
	            var checkedList = new Array();
	            //每一个被选中的name为ids的input标签
	            $("input[name='ids']:checked").each(function(){
	                checkedList.push($(this).val());//将id存入数组
	            });
	            $.ajax({
	                type:"post",
	                dataType:"json",
	                url:"${pageContext.request.contextPath}/deleteShips.action",//不同页面只用更改action即可
	                async:true,
	                //数组的toString里的id是用","分隔开的，例如数组{"1","2","3"},同String后为"1,2,3"
	                data:{"deleteList":checkedList.toString()},
	                success:function(data){
	                    if(data==1){
	                        for(var i=0;i<checkedList.length;i++){
	                            $("#tr_"+checkedList[i]).remove();//ajax动态移除
	                        }
	                        alert("删除成功");
	                    }else{
	                        alert("删除失败");
	                    }
	                },
	                error:function(){
	                    alert("error");
	                }
	             })
	         }
	     })
	              			
	})
	
	function addShip(){
		$.ajax({
			url:"${pageContext.request.contextPath}/addShip.action",
			method:"post",
			data:{
				"shipaddress":$("#shipaddress").val(),
				"shipname":$("#shipname").val(),
				"shipphone":$("#shipphone").val()

			},
			success:function(response){
				console.log(response);
				let $registMe=response.objectMap.registMe;
				if(response.errorCode==="100"){
					alert($registMe);
					window.location="${pageContext.request.contextPath}/showAddress.action";
				}else{
					alert($registMe);
				}
			},
			error:function(){
				console.log("请求发送失败..")
			}
		});
	}
</script>
</head>
<body>

	<div class="container header">
		<div class="span5">
			<div class="logo">
				<a href="${pageContext.request.contextPath}/index.action"> <img
					src="${pageContext.request.contextPath}/image/r___________renleipic_01/logo.gif"
					alt=""></a>
			</div>
		</div>
		<div class="span9">
			
		</div>
		<%@ include file="menu.jsp"%>
	</div>
	<div class="container cart">
			<form id="Form1" name="Form1"
		action="${pageContext.request.contextPath}/order/list.jsp"
		method="post">
		<table width="100%" align="center" border="0">
			<TBODY>
				<tr>
					<td class="ta_01" align="center" bgColor="#f5fafe">
						<table width="100%" align="center" class="table-bordered"
							id="table" style="border: 1px solid #D0D0D0">
							<tr align="center" bgcolor="#93b6bd" height="40px;">
								<td align="center" width="5%">序号</td>
								<td align="center" width="30%">收货地址</td>
								<td align="center" width="15%">收货人</td>
								<td align="center" width="15%">电话</td>
								<td align="center" width="10%">操作</td>
							</tr>

							<c:forEach items="${shiplist}" var="o" varStatus="status">
								<tr onmouseover="this.style.backgroundColor = 'white'"
									onmouseout="this.style.backgroundColor = '#F5FAFE';" id="tr_${o.id}">
									<td style="CURSOR: hand; HEIGHT: 40px" align="center"
										width="5%"><input name="ids" value="${o.id}" type="checkbox" /></td>
									<td style="CURSOR: hand; HEIGHT: 22px" align="center"
										width="30%" name="shipaddress">${o.shipaddress}</td>
									<td style="CURSOR: hand; HEIGHT: 22px" align="center"
										width="10%" name="shipname">${o.shipname}</td>
									<td style="CURSOR: hand; HEIGHT: 22px" align="center"
										width="10%" name="shipphone">${o.shipphone}</td>
									<td style="CURSOR: hand; HEIGHT: 22px" align="center"
										width="20%">
										<input value="编辑" type="button"  onclick="update(${o.id})" 
										style="color:#fff;background-color: #337ab7;border-color: #337ab7;"/>
										<input value="删除" type="button"  onclick="dele(${o.id})" 
										style="color:#fff;background-color: #d9534f;border-color: #d9534f;"/>
										<input value="选择" type="button"  onclick="choose(${o.id})"
										style="color:#fff;background-color: #7cab2a;border-color: #7cab2a;"/>
									</td>
								</tr>
							</c:forEach>
						</table>
					</td>
				</tr>
			</TBODY>
		</table>
	</form>
	<div align="right"><input id="deleteSkills" type="button" value="-批量删除-" 
			style="color:#fff;background-color: #d9534f;border-color: #d9534f;margin-right:43px;margin-top:10px;"/></div>
	<br/> 
	<form id="Form2" name="Form2"
		align="center">
		收货地址：<input name="shipaddress" id="shipaddress" type="text"  style="width:230px" value="${shipinfos.shipaddress }"/>
		<br/><br/> 
		收货人&nbsp;&nbsp;&nbsp;：<input name="shipname" id="shipname" type="text"  style="width:230px" value="${shipinfos.shipname }"/>
		<br/> <br/> 
		联系方式：<input name="shipphone" type="text" id="shipphone" style="width:230px" value="${shipinfos.shipphone }"/>
		<br/> <br/> 
		
		<input value="添加收货地址" type="submit" onclick="addShip()"
										style="color:#fff;background-color: #337ab7;border-color: #337ab7;"/>

		
		</form>
	</div>

	<div class="container footer">
		<div class="span24">
			
		</div>
		<div class="span24">
			<ul class="bottomNav">
				<li><hr></hr></li>
			</ul>
		</div>
		<div class="span24">
			<div class="copyright">Copyright © 网上商城 版权所有</div>
		</div>
	</div>
</body>
</html>